/**Copyright 2007 Ultrapower Software Co. Ltd.
 * All right reserved. 
 *
 * 2007-9-15,上午10:50:46
 */
package com.osgix.common.pojo.temp;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * <b> 权限解析类</b>
 * <b> 此类为一个权限点权限的帮助类，封装查找权限点每个操作位的取值方法</b>
 *
 * <b>@author zqmao 2007-9-15,上午10:50:46</b>
 *
 * <b>version 1.0</b>
 */
public class PrivilegeHelper implements Serializable {

	/**
	 * 2009-4-29,下午03:42:06
	 * @author Administrator
	 * @version 2.0
	 *
	 */
	private static final long serialVersionUID = -7800694788178915764L;

	/**
	 * 权限点ID
	 */
	private String ppId = "";

	/**
	 * 资源访问类型
	 */
	private String accessType = "";

	/**
	 * 权限值
	 */
	private long privilege = 0;

	/**
	 * 操作权限映射表 Map<operateId,Boolean>
	 */
	private Map privilegeMap = new HashMap();

	/**
	 * 权限最细粒度标识ID Map<operateId,perimissionId>
	 */
	private Map permissionMap = new HashMap();

	/**
	 * 构造函数
	 *
	 */
	public PrivilegeHelper() {

	}

	/**
	 * 构造函数
	 * @param ppId
	 * @param accessType
	 * @param privilege
	 */
	public PrivilegeHelper(String ppId, String accessType, long privilege) {
		this.ppId = ppId;
		this.accessType = accessType;
		this.privilege = privilege;
	}

	/**
	 * 取得一个操作的权限值，如果查询操作ID不在映射Map中，返回false
	 * @param operateId 操作ID
	 * @return true: 拥有此权限，false :没有权限
	 */
	public boolean getOperatePrivilege(String operateId) {
		Boolean oPri = (Boolean) privilegeMap.get(operateId);
		if (oPri == null)
			return false;
		return oPri.booleanValue();
	}

	/**
	 * 设置权限点操作位的权限值
	 * @param operateId 操作ID
	 * @param bPrivilege 权限值 true:有权限；false: 没有权限
	 */
	public void putOperatePrivilege(String operateId, boolean bPrivilege) {
		privilegeMap.put(operateId, new Boolean(bPrivilege));
	}

	/**
	 * 设置权限点操作位对应的permissionId
	 * @param operateId 操作ID
	 * @param operBit 操作位
	 
	public void putPermissionId(String operateId,int operBit) {
		permissionMap.put(operateId,createPermissionId(operBit)); 
	}
	*/

	/**
	 * 创建PermissionId,首先将ppId转换为一个long值，然后前移二位再加上操作ID作为一个能够唯一标识一个资源的操作的permissionId.
	 * @param operBit
	
	private Long createPermissionId(int operBit) {
		long lResId = UUIDPK.getString2Long(ppId);
		return (lResId * 100) + operBit;
	}
	 */

	public String getPpId() {
		return ppId;
	}

	public void setPpId(String ppId) {
		this.ppId = ppId;
	}

	public long getPrivilege() {
		return privilege;
	}

	public void setPrivilege(long privilege) {
		this.privilege = privilege;
	}

	public Map getPrivilegeMap() {
		return privilegeMap;
	}

	public void setPrivilegeMap(Map privilegeMap) {
		this.privilegeMap = privilegeMap;
	}

	public String getAccessType() {
		return accessType;
	}

	public void setAccessType(String accessType) {
		this.accessType = accessType;
	}

	public Map getPermissionMap() {
		return permissionMap;
	}

	public void setPermissionMap(Map permissionMap) {
		this.permissionMap = permissionMap;
	}

	public String toString() {
		return ppId + "/" + accessType + "/" + privilege + "/" + privilegeMap + "\n";
	}
}
